package com.palandrodev.calsmart;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.palandrodev.calsmart.util.Constants;

public class CalsmartMainActivity extends Activity {

	private List<String> menuItems;
	private ListView menuListView;
	private ArrayAdapter<String> adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.calsmart_main);
		initialize();

	}

	private void initialize() {
		setMenuItems(new ArrayList<String>());
		menuItems.add("Simple Interest Calculator");
		menuItems.add("Compound Interest Calculator");
		menuItems.add("Tip Calculator");
		adapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, menuItems);
		menuListView = (ListView) findViewById(R.id.mainMenuListView);
		menuListView.setAdapter(adapter);
		menuListView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				switch (position) {
				case 0:
					CalsmartMainActivity.this.startActivityForResult(
							new Intent(CalsmartMainActivity.this,
									SimpleInterestActivity.class), 0);
					break;
				case 1:
					CalsmartMainActivity.this.startActivityForResult(
							new Intent(CalsmartMainActivity.this,
									CompoundInterestActivity.class), 0);
					break;
				case 2:
					CalsmartMainActivity.this.startActivityForResult(
							new Intent(CalsmartMainActivity.this,
									TipCalculatorActivity.class), 0);
					break;
				default:
					break;
				}

			}
		});

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.settings, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {

		case R.id.menu_settings:
			Intent i = new Intent(this, ShowSettingsActivity.class);
			startActivityForResult(i, Constants.RESULT_SETTINGS);
			break;

		}

		return true;
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		switch (requestCode) {
		case Constants.RESULT_SETTINGS:
			
			break;

		}

	}

	public List<String> getMenuItems() {
		return menuItems;
	}

	public void setMenuItems(List<String> menuItems) {
		this.menuItems = menuItems;
	}

}
